package master.usefulClosures;

import java.awt.Graphics;
import java.awt.event.*;

public class AnimatedComplexNumberLog extends AnimatedComplexNumber{

	float [] reals;
	float [] ims;
	int n;
	
	public AnimatedComplexNumberLog(float re, float im, float inc, int n) {
		super(re, im, inc);
		reals = new float[n];
		ims = new float[n];
		this.n = n;
		for(int i = 0 ; i < n ; i++){
			reals[i] = 0;
			ims[i] = 0;
		}
	}
	
	public void actionPerformed(ActionEvent e){
		super.actionPerformed(e);
		n=n+1;
		n=n%reals.length;
		reals[n] = getReal();
		ims[n] = getImaginary();
	}
	
	public void draw(Graphics g, int x, int y, float multiplier){
		super.draw(g, x, y, multiplier);

		for(int i = 1 ; i < reals.length-1 ; i++){
			
			int drawX =  x + (int)(reals[i]*multiplier);
			int drawY = y - (int)(ims[i]*multiplier);
			int drawX2 =  x + (int)(reals[i+1]*multiplier);
			int drawY2 = y - (int)(ims[i+1]*multiplier);
			
			g.drawLine(drawX, drawY, drawX2, drawY2);
		}
		
	}
	
}
